import Guide from '@/components/Guide';
import {trim} from '@/utils/format';
import {PageContainer} from '@ant-design/pro-components';
import {useModel} from '@umijs/max';
import styles from './index.less';
import React, {useEffect} from "react";
import {useLocation} from "@@/exports";
import {parseImToken} from "@/services/demo/UserController";
import {Button, message} from "antd";

const HomePage: React.FC = () => {
    const {name} = useModel('global');
    const localtion = useLocation();
    useEffect(() => {
        const searchParams = new URLSearchParams(location.search);
        const randomUUID = searchParams.get('random');
        // componentDidMount
        console.log('Component mounted',randomUUID);
        if(randomUUID){
            parseToken(randomUUID)
        }
        // componentDidUpdate
        return () => {
            // componentWillUnmount
            console.log('Component unmounted');
        };
    }, []);

   const parseToken=async (uuid: string) => {
       const {code, message: msg, result} = await parseImToken(uuid);
       if (200 !== code) {
           message.error(msg)
       }
       localStorage.setItem("connection-imtoken", result)
   }

    return (
        <PageContainer ghost>
            <div className={styles.container}>
                <Guide name={trim(name)}/>
            </div>
        </PageContainer>
    );
};

export default HomePage;
